﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace CloverNet.Authorization
{
    public class PermissionProviderCollection : Collection<IPermissionProvider>
    {
        private object[] _permissions;

        public object[] Permissions
        {
            get => _permissions ?? (_permissions = GetPermissions());
        }

        public PermissionProviderCollection() { }

        public PermissionProviderCollection(IList<IPermissionProvider> _permissionProviders) : base(_permissionProviders) { }

        public virtual object[] GetPermissions()
        {
            return Items.Select(m => m.GetPermissions())
                 .Aggregate((m, n) => m.Concat(n))
                 .ToArray();
        }

    }
}
